from flask import Blueprint, jsonify
from ..services.inventory_service import InventoryService

inventory_bp = Blueprint('inventory', __name__)

@inventory_bp.route('/<string:material_type>', methods=['GET'])
def get_inventory(material_type):
    """
    获取指定类型的库存数据
    :param material_type: 类型标识（量产材料/成品等）
    :return: JSON格式库存数据
    """
    try:
        data = InventoryService.get_by_type(material_type)
        return jsonify({'code': 200, 'data': data})
    except ValueError as e:
        return jsonify({'code': 400, 'error': str(e)}), 400